package com.itheima.map;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo04 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //156  ConcurrentHashMap
        Hashtable<String, String> map = new Hashtable<>();
        FutureTask task = new FutureTask<>(() -> {
            long start = System.currentTimeMillis();
            for (int i = 1; i <= 50000; i++) {
                map.put(i + "", i + "");
            }
            long end = System.currentTimeMillis();
            return end-start;
        }
        );
        new Thread(task).start();

        FutureTask task2 = new FutureTask<>(() -> {
            long start = System.currentTimeMillis();
            for (int i = 50000; i <= 100000; i++) {
                map.put(i + "", i + "");
            }
            long end = System.currentTimeMillis();
            return end-start;
        }
        );
        new Thread(task2).start();
        FutureTask task3 = new FutureTask<>(() -> {
            long start = System.currentTimeMillis();
            for (int i = 500000; i <= 550000; i++) {
                map.put(i + "", i + "");
            }
            long end = System.currentTimeMillis();
            return end-start;
        }
        );
        new Thread(task3).start();
        FutureTask task4 = new FutureTask<>(() -> {
            long start = System.currentTimeMillis();
            for (int i = 5000000; i <= 5050000; i++) {
                map.put(i + "", i + "");
            }
            long end = System.currentTimeMillis();
            return end-start;
        }
        );
        new Thread(task4).start();
        FutureTask task5 = new FutureTask<>(() -> {
            long start = System.currentTimeMillis();
            for (int i = 50000000; i <= 50050000; i++) {
                map.put(i + "", i + "");
            }
            long end = System.currentTimeMillis();
            return end-start;
        }
        );
        new Thread(task5).start();

        System.out.println(task.get());///
        System.out.println(task2.get());//
        System.out.println(task3.get());//
        System.out.println(task4.get());//
        System.out.println(task5.get());//

    }
}
